package cn.tedu.zx.ams.adapter.controller;

import cn.tedu.zx.ams.service.LoginLogService;
import cn.tedu.zx.common.restful.JsonResult;
import cn.tedu.zx.pojo.admin.parm.AdminAddNewParam;
import cn.tedu.zx.pojo.admin.parm.LoginLogAddNewParam;
import cn.tedu.zx.pojo.admin.vo.LoginLogListItemVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/LoginLog")
@Api(tags = "04. 登录日志模块")
@Slf4j
@Validated
public class LoginLogController {
    @Autowired
    private LoginLogService loginLogService;

    @PostMapping("/record")
    @ApiOperation("添加登录日志")
    @ApiOperationSupport(order = 100)
    public JsonResult<Void> addNew(@Valid LoginLogAddNewParam loginLogAddNewParam) {
        log.debug("开始处理【添加登录日志】的请求，参数：{}", loginLogAddNewParam);
        loginLogService.addNew(loginLogAddNewParam);
        return JsonResult.ok();
    }

    @GetMapping("/list")
    @ApiOperation("查询登录日志")
    @ApiOperationSupport(order = 400)
    public JsonResult<List<LoginLogListItemVO>> list() {
        log.debug("开始处理【查询登录日志】的请求");
        return JsonResult.ok(loginLogService.list());
    }
}
